package com.wh.wisdomsite.xbox.client.service.configClient.me;

import com.wh.wisdomsite.xbox.ba.service.ICommonDictService;
import com.wh.wisdomsite.xbox.client.utils.ConfigUserUtils;
import com.wh.wisdomsite.xbox.common.Constants;
import com.wh.wisdomsite.xbox.common.annotation.NeedInSessionType;
import com.wh.wisdomsite.xbox.common.annotation.ServiceMethod;
import com.wh.wisdomsite.xbox.common.annotation.ServiceProvider;
import com.wh.wisdomsite.xbox.common.reponse.CommonResult;
import com.wh.wisdomsite.xbox.me.service.ICraneStandardService;
import com.wh.wisdomsite.xbox.pojo.configClient.me.CclCraneIn;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 手机配置端起重机械service
 * @author 刘旭
 * @version V1.0
 * @Package com.wh.wisdomsite.xbox.client.service.configClient.me
 * @date 2018年11月07日 16:13
 * @Copyright 企业版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2018
 */
@ServiceProvider()
public class ConfigClientCraneService {
    private static final Log logger = LogFactory.getLog(ConfigClientCraneService.class);

    @Autowired
    private ICommonDictService iCommonDiceService;

    @Autowired
    private ICraneStandardService iCraneStandardService;

    /**
     * 获取起重机械标准配置列表
     * @param in
     * @return
     */
    @ServiceMethod(method = "zhgd.configClient.me.getCraneStandardList", title = "获取起重机械标准配置列表", version = "1.0", needInSession = NeedInSessionType.YES)
    public CommonResult getCraneStandardList(CclCraneIn in) {
        CommonResult commonResult = new CommonResult();
        List<Map<String,Object>> craneStandardList = new ArrayList<>();
        try{
            //设置条件
            logger.info("获取起重机械标准配置列表->>zhgd.configClient.me.getCraneStandardList->>开始");
            Integer companyId = ConfigUserUtils.getCurrentUser(in).getCompanyId();
            List<Map<String,Object>> craneStandards = iCraneStandardService.cclGetStandardList(companyId);
            if (craneStandards.size() > 0) {
                craneStandardList = craneStandards;
            }
            commonResult.setCode(Constants.CODE_SUCCESS);
            commonResult.setMessage(Constants.CODE_SUCCESS_MSG);
            commonResult.setResult(craneStandardList);
            logger.info("获取起重机械标准配置列表->>zhgd.configClient.me.getCraneStandardList->>结束");
        }catch (Exception e){
            logger.error("获取起重机械标准配置列表->>zhgd.configClient.me.getCraneStandardList->>异常："+e.getMessage());
            commonResult.setCode(Constants.CODE_FAIL);
            commonResult.setMessage(Constants.CODE_FAIL_MSG);
            in.getXboxRequestContext().setException(new Exception(e.getMessage()));
            e.printStackTrace();
        }
        return commonResult;
    }

}
